The present invention relates in general to computer memory management, and more particularly to dynamic scheduling of memory pinning.
Traditionally, pinning memory is a privileged capability that is not available to normal user tasks but only to the OS kernel, e.g., for device drivers. Pinning generally refers to an ability for pages to remain in main memory and not have to be swapped out, typically by a computer operating system. Pinning is controlled by the facts that the components are statically known, that they are trusted, and that they have most restrictive policies for minimizing pinning.
However, other applications can also benefit from more liberal pinning policies. Such applications include device drivers run at user level which use direct memory access (DMA), real-time systems that rely on no-page-fault guarantees, and database-like applications that perform drastically better when some application-specific pages are pinned for a shorter or longer time interval. Therefore, it is highly desirable to provide static and dynamic pinning capabilities to applications as well.
Static pinning is used for pinning driver or real-time code and data, certain buffers, etc. In static pinning, pages are pinned for a very long time, if not permanently. A method is usually necessary to guarantee a basic functionality of some components. For example, static pinning can be controlled by traditional quota-based methods.
Dynamic pinning has two characteristic properties: pages are pinned for short periods only, and it is dynamically decided which and how many pages are pinned. Dynamic pinning is highly desirable and useful in many instances, including the following:
1. For transmitting a file, e.g., over a network. The network system pins the file partially (or entirely) in memory for the transmission period. This enables zero-copy transmission, i.e., avoids copying data into network buffers, and therefore, increases the performance substantially.
2. For communicating data to a non-real-time component, a real-time application temporarily requests pinned memory.
3. A real-time application temporarily asks for pinned memory. Although, the application would meet its deadlines and fulfill its minimal quality-of-service contracts without this memory, additional buffers can substantially improve its quality of service or reduce the overall system load, i.e., make more processor time available for non-real-time tasks.
4. Based on its application-specific knowledge, a database system decreases overall swapping by pinning dynamically some of its pages.
In all of the following cases, applications negotiate with the system whether, how many and how long pages can be pinned for them. Furthermore, dynamic pinning needs to be controlled by a policy that coordinates the requests of multiple independent applications, restricts the negative effects that pinning has on other paged applications. In addition the controlling policy needs to be a policy which can be enforced against untrusted applications. Accordingly, it is highly desirable to provide dynamic pinning with scheduling policies.
For example, if a user task can dynamically ask to pin some of its currently mapped pages for a certain period of time, a scheduling algorithm in the pager is needed to decide whether the request will be granted, denied, or granted with less pages or for a shorter period. Such a dynamic-pinning scheduler should have some of the following properties.
1. It should work in combination with any reasonable page-replacement algorithm.
2. It should not rely on pinning-related trust in the applications. For instance, restricting pinning to device drivers is not acceptable.
3. It should be robust against denial-of-service attacks. Pinning must not offer new possibilities for monopolyzing a system.
4. It should adapt quickly to changing system load. An application should be granted a high amount of pinned pages if enough unused memory is available. Conversely, less pinning should be granted if memory is getting short.
5. The basic scheduler should be enabled to add specific policies that, e.g., handle applications that are prioritized or weighted differently.
Therefore, to resolve the above issues, it is highly desirable to have a pinning policy which includes time boundaries. Furthermore, applications cannot be relied upon to unpin their pages on a timely basis. Therefore, it is highly desirable to have enforcement policies which can necessitate unpinning. As is apparent to those skilled in the field of art, the properties 3 and 4 above exclude simple solutions such as giving each application a fixed quota of n/m pinned pages in a context of n physical pages and m applications.
Accordingly, to resolve the above shortcomings, the present invention is a method and apparatus for providing a dynamic scheduling of memory pinning where the applications may request for and be allowed to pin pages in memory based on predetermined criteria and according to given constraints.
The pin engine of the present invention evaluates whether to grant a pinning request based on preexisting criteria such as availability of system resources, and returns a response to the application indicating whether the pinning request was granted. With the granting of the pinning request, the pin engine specifies certain constraints which the application must uphold. Such constraints may include a requirement that the application unpin all or some of its pages after an expiration of time predetermined by the pin engine, again based on existing criteria which may include system resources, and the current load of the system. The pin engine also has an enforcement capability to unpin the pages pinned by the applications, whenever a necessity arises.
More specifically, the present invention provides the compensated pinning mechanism wherein an application desiring to pin certain number of its pages offers substitute pages for replacement. An application initially makes a pinning request to a pin engine, including with its request, desired properties such as the actual pages for pinning, number of pages for pinning, and duration of time for a requested page to remain pinned. The application also includes the pages which are currently mapped as compensation pages which may serve as substitute for the pinned page during page replacement.
In addition, the present invention provides color-sensitive compensation mechanism wherein a compensation page having the same color as the pinned page is used for replacement. Having the same color compensation page avoids potential subsequent cache conflicts and can result in performance improvement.
For providing the above functionalities, the present invention includes a pin engine which grants or denies pin requests from the applications based on evaluation performed according to the available system resources, a compensation selector for selecting a compensating page, i.e., a substitute page. When a page replacer which according to any known replacement algorithm picks a page for swapping and the picked page is a pinned or to-be-pinned page, the compensation selector selects another page for the page replacer to use in place of the replacer picked page. The compensation selector selects the compensating page from a compensation set, which typically includes the compensation pages offered by the application requesting the pinning. The compensation selector also may select the compensating page from a compensation pool having a larger set of compensation pages supplied by any of the system resources or applications.
Furthermore, when selecting a compensating page, the compensation selector may rank the compensation pages based on any number of predetermined criteria. Such criteria may include but not limited to color sensitivity. For example, a compensation page having the same color as the page replacer picked page which is pinned or to-be-pinned may be ranked high whereas other pages may be ranked low. Accordingly, the compensation selector selects the highly ranked pages before selecting the others.
Further features and advantages of the present invention as well as the structure and operation of various embodiments of the present invention are described in detail below with reference to the accompanying drawings. In the drawings, like reference numbers indicate identical or functionally similar elements.